package org.xdj.blue.dubbo.filter;

import java.io.IOException;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;

public class RestCorsFilter implements ContainerResponseFilter {
	
    //@Override
    public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
       
    	System.out.println("--RestCorsFilter--");
    	containerResponseContext.getHeaders().add("Access-Control-Allow-Origin", "*");
        String method = containerRequestContext.getMethod();
        if("OPTIONS".equalsIgnoreCase(method)) {
            containerResponseContext.getHeaders().add("Access-Control-Allow-Methods", "POST,GET");
            containerResponseContext.getHeaders().add("Access-Control-Allow-Headers", "accept,"+"content-type");
            containerResponseContext.setStatus(200);
            return;
        }
    }
}